package com.toutiao.model

import scala.collection.mutable.{HashMap => HMap}

import com.toutiao.score.Topic

class TimeDB(root:String, cacheSize:Int) {
  
  val mData = new HMap[String,FeatureDB]
  def init(t:String) = {
      val db = new FeatureDB(root+"/"+t,cacheSize)
      mData(t) = db
  }
  
  def isIn(t:String) = mData.contains(t)
  def apply(t:String) = mData(t)
  def keySet = mData.keySet
  
  def insert(t:String, n:String, topic:Topic) {
    if (!mData.contains(t)){
      init(t)
    }
    mData(t).insert(n, topic)
  }
  
  def remove(t:String, n:String) {
    if (mData.contains(t)){
      mData(t).remove(n)
    }
  }
  
  def remove(t:String) {
    if (mData.contains(t)) {
      mData(t).close
      mData.remove(t)
    }
  }
  
}
